#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 60;
int a[N];

int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t; cin >> t;
	while (t--)
	{
		int n; cin >> n;
		memset(a, 0, sizeof a);
		for (int i = 1; i <= n; ++i)
			cin >> a[i];

		sort(a + 1, a + n + 1);
		if (n == 1)
		{
			cout << 0 << '\n';
			continue;
		}
		else if (n == 2 || n == 3)
		{
			cout << a[n] - a[1] << '\n';
			continue;
		}
		else
		{
			int sum = 0;
			for (int i = 1; i <= n / 2; ++i)
				sum += (a[n - i + 1] - a[i]);
			cout << sum << '\n';
			continue;
		}
	}

	return 0;
}